package com.example.dell.fastshopping.user.modle;

import android.arch.lifecycle.LiveData;
import android.arch.lifecycle.MutableLiveData;
import android.arch.lifecycle.ViewModel;

import com.example.dell.fastshopping.network.ApiService;
import com.example.dell.fastshopping.network.NetCallback;
import com.example.dell.fastshopping.network.RetrofitClient;
import com.example.dell.fastshopping.network.http.BaseResponse;
import com.example.dell.fastshopping.user.entity.IntegralBaseInformation;
import com.example.dell.fastshopping.user.entity.IntegralDetail;

import java.util.ArrayList;
import java.util.List;

public class IntegralActivityMolder extends ViewModel {
    private ApiService service = RetrofitClient.getInstance().create(ApiService.class);
    private MutableLiveData<List<IntegralDetail>> integralList = new MutableLiveData<>();
    private MutableLiveData<IntegralBaseInformation> userintegral = new MutableLiveData<>();

    public LiveData<List<IntegralDetail>> getList(int pageNum, int pageSize) {
        RetrofitClient.execute(service.findIntegralDetailPage(pageNum, pageSize), new NetCallback<BaseResponse<IntegralDetail>>() {
            @Override
            public void netCallback(BaseResponse<IntegralDetail> response) {
                integralList.setValue(response.getData().getList());
            }
        });
        return integralList;
    }

    public MutableLiveData<IntegralBaseInformation> getUserIntegral() {
        RetrofitClient.execute(service.getUserIntegral(), new NetCallback<BaseResponse<IntegralBaseInformation>>() {
            @Override
            public void netCallback(BaseResponse<IntegralBaseInformation> response) {
                userintegral.setValue(response.getData());
            }
        });
        return userintegral;
    }
}
